home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / COMMON.ZIP / MODEM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-23  |  5.2 KB  |  218 lines

  1. //for use with serial.c by Alec Russell.
  2.  
  3. #if 0
  4. /*
  5.  
  6. code snippets to demo some common functions
  7.  
  8.  
  9. // returns non-zero if online, ese zero
  10. /* ---------------------- online() ----------------------- April 23,1995 */
  11. int online(void)
  12. {
  13.    msr();  // sets global var sio_modemstat
  14.    return (sio_modemstat & 128);    // check online bit
  15. }
  16.  
  17.  
  18. char gb_util_str[1024];
  19.  
  20. // this is just to give some clues - much is in libraries I can't give out
  21. // dial_d holds phone number, baud etc...
  22. // twput() prints text in a window
  23. /* ---------------------- dial_one_entry() ------------- October 21,1992 */
  24. int dial_one_entry(dial_t *d, serial_232_t *sd)
  25. {
  26.     int ok, connected, a, i, len, got_text, esc, attempt;
  27.     int color, p_color;
  28.     char last_ret[50];
  29.     clock_t time_out;
  30.  
  31.     color=BCK_BLUE | WHITE;
  32.     p_color=BCK_BLUE | YELLOW;
  33.  
  34.     ok=FALSE;
  35.  
  36.     // dial dir holds boud etc... for each entry
  37.    //  change to correct setting if neccessary
  38.     if ( sd->baud != d->baud )
  39.         {
  40.         /* change baud rate */
  41.         deinit_232();
  42.         sd->baud=d->baud;
  43.         if ( init_232(sd) )
  44.             {
  45.             ok=FALSE;
  46.             return(ok);
  47.             }
  48.  
  49.         /* update status line */
  50.         a=get_old_idt();
  51.         select_twindow(25000);
  52.         print_status_line(sd);
  53.         select_twindow(a);
  54.         }
  55.  
  56.     twput(2, 15, color, "══════════════════════════════════════");
  57.     twput(2, 15, color, "╡ ESC to exit ╞");
  58.  
  59.  
  60.     strcpy(last_ret, "NONE");
  61.     connected=FALSE;
  62.     esc=FALSE;
  63.     attempt=0;
  64.     do
  65.         {
  66.         clear_wt(0);
  67.         flush_232_rcv();
  68.         delay(t_parm.dial_pause);
  69.  
  70.         if ( bioskey(1) )  // if a key is pressed
  71.             {
  72.             a=getk();
  73.             if ( a == ESC )
  74.                 esc=TRUE;
  75.             }
  76.  
  77.  
  78.         /* print status on screen */
  79.         twput(3,2, p_color, "DIALING:");
  80.         sprintf(gb_util_str, "%s at %s", d->name, d->number);
  81.         twput(12,2, color, gb_util_str);
  82.         twput(3,4, p_color, "Attempt #");
  83.         sprintf(gb_util_str, "%d", ++attempt);
  84.         twput(12,4, color, gb_util_str);
  85.         twput(3,6, p_color, "Last Result:");
  86.         sprintf(gb_util_str, "%s", last_ret);
  87.         twput(16,6, color, gb_util_str);
  88.  
  89.         /* send dial string to modem */
  90.         sprintf(gb_util_str, "ATD%c%s\r",
  91.                 t_parm.tone ? 'T' : 'P',
  92.                 d->number);
  93.         got_text=0;
  94.         len=strlen(gb_util_str);
  95.         for ( i=0; i < len; i++ )
  96.             send_232((int)gb_util_str[i]);
  97.  
  98.  
  99.         // this is OLD code, and can be more generic/robust
  100.         /* wait for reply from modem */
  101.         time_out=clock() + t_parm.dial_timeout;
  102.         i=0;
  103.         memset(gb_util_str, 0, 256);
  104.         do
  105.             {
  106.             if ( char_ready_232() )
  107.                 {
  108.                 gb_util_str[i]=get_232();
  109.                 i++;
  110.  
  111.                 if ( strstr(gb_util_str, "BUSY") )
  112.                     {
  113.                     strcpy(last_ret, "BUSY");
  114.                     got_text=TRUE;
  115.                     }
  116.                 if ( strstr(gb_util_str, "NO CARRIER") )
  117.                     {
  118.                     strcpy(last_ret, "NO CARRIER");
  119.                     got_text=TRUE;
  120.                     }
  121.  
  122.                 if ( strstr(gb_util_str, "CONNECT") || strstr(gb_util_str, "2400") ||
  123.                      strstr(gb_util_str, "1200") || strstr(gb_util_str, "NNECT") )
  124.                     {              
  125.                     strcpy(last_ret, "CONNECTED");
  126.                     got_text=TRUE;
  127.                     connected=TRUE;
  128.                     ok=TRUE;
  129.                     }
  130.                 }
  131.  
  132.             if ( bioskey(1) )
  133.                 {
  134.                 a=getk();
  135.                 if ( a == ESC )
  136.                     esc=TRUE;
  137.                 }
  138.  
  139.             }
  140.         while ( !got_text && !esc && i < 256 && clock() < time_out );
  141.  
  142.         if ( clock() >= time_out )
  143.             strcpy(last_ret, "TIMED OUT");
  144.  
  145.         }
  146.     while ( !connected && !esc );
  147.  
  148.  
  149.     return(ok);
  150. }
  151.  
  152.  
  153.  
  154. // just to get someone started
  155. // assumes serial stuff already inited
  156. /* ---------------------- simple_term() ------------------ April 23,1995 */
  157. void simple_term(void)
  158. {
  159.    short done=0;
  160.    short a=0;
  161.    short k=0;
  162.  
  163.    do
  164.       {
  165.       if ( bioskey(1) )
  166.          {
  167.          // user pressed a key
  168.          a=getch();
  169.          if ( !a )
  170.             a=getch();
  171.          if ( isascii(a) )
  172.             {
  173.             printf("%c", a);
  174.             send_232(a);
  175.             }
  176.  
  177.          switch ( a )
  178.             {
  179.             case ESC:
  180.                done=1;
  181.                break;
  182.  
  183.             case F1:
  184.                print_help();
  185.                break;
  186.  
  187.             case ALT_S:
  188.                do_file_transfer();
  189.                break;
  190.  
  191.             case ALT_O:
  192.                edit_modem_parms();
  193.                break;
  194.  
  195.             // put as many functions as you like in here
  196.             }
  197.          }
  198.  
  199.  
  200.       if ( char_ready_232() )
  201.          {
  202.          k=get_232();
  203.          if ( isascii(k) )
  204.             {
  205.             printf("%c", k);
  206.             }
  207.          }
  208.  
  209.       }
  210.    while ( !done );
  211.  
  212. }
  213.  
  214.  
  215. */
  216. #endif
  217.  
  218.